<template>
  <el-dialog
    title="题目预览"
    :visible="subjectShow"
    @open="openDialog"
    @close="close"
  >
    <div class="main">
      <el-row class="header">
        <el-col> 【题型】:{{ titlepreview.questionType | formatText }} </el-col>
        <el-col> 【编号】:{{ titlepreview.id }} </el-col>
        <el-col> 【难度】:{{ titlepreview.difficulty | FormatText }} </el-col>
        <el-col> 【标签】:{{ titlepreview.tags }} </el-col>
        <el-col>【学科】:{{ titlepreview.subjectName }}</el-col>
        <el-col> 【目录】:{{ titlepreview.directoryName }} </el-col>
        <el-col> 【方向】:{{ titlepreview.direction }} </el-col>
      </el-row>
      <hr />
      <div v-html="titlepreview.question">【题干】:</div>
      <div>
        {{
          titlepreview.questionType | formatText
        }}选项:（以下选中的选项为正确答案）
      </div>
      <div class="radio_flex_col" v-if="titlepreview.questionType - 0 === 1">
        <el-radio-group
          style="margin: 10px"
          v-model="item.isRight"
          v-for="item in titlepreview.options"
          :key="item.id"
        >
          <el-radio :label="item.isRight === 1 ? 1 : ''" class="radio">
            <p>{{ item.title }}</p>
            <el-image
            v-if="item.img"
            style="width: 100px; height: 60px;position:absolute;right:0;top:0;"
            :src="!item.img ? '' : item.img"
            :lazy='true'
            :preview-src-list="[item.img]"
            >
            </el-image>
          </el-radio>
        </el-radio-group>

      </div>
      <div v-else-if="titlepreview.questionType - 0 === 2">
        <div class="radio_flex" v-for="item in titlepreview.options"  :key="item.id">
          <el-checkbox
          :checked="item.isRight === 1 ? true : false"
          />
          <p>{{ item.title }}</p>
          <el-image
            :lazy='true'
            v-if="item.img"
            style="width: 100px; height: 60px"
            :src="item.img"
            :preview-src-list="[item.img]"
            />
        </div>
      </div>
      <div v-else>
        <p v-html="titlepreview.question"></p>
      </div>
      <hr />
      <span>
        【参考答案】:
        <el-button type="danger" @click="show">视频答案预览</el-button>
      </span>
      <div v-show="isshow">
        <video :src="titlepreview.videoURL" preload="auto" controls></video>
      </div>
      <hr />
      <div>【答案解析】:{{ titlepreview.remarks }}</div>
      <hr />
      <div>【题目备注】:{{ titlepreview.remarks }}</div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
export default {
  name: 'DialogShow',
  model: {
    prop: 'subjectShow'
  },
  props: {
    subjectShow: {
      type: Boolean,
      required: true
    },
    subjectId: {
      type: [Number, String],
      required: true
    }
  },
  data () {
    return {
      isshow: false,
      titlepreview: {},
      list: []
    }
  },

  created () {},

  methods: {
    show () {
      this.isshow = true
    },
    // 关闭弹窗通过v-model返回值input
    close () {
      this.$emit('input', false)
      this.isshow = false
      this.titlepreview = {}
    },
    // 获取题目详情
    async openDialog () {
      console.log(this.subjectId)
      const res = await detail({ id: this.subjectId })
      this.titlepreview = res.data
      console.log(res.data)
    }
  }
}
</script>

<style scoped lang="scss">
.main {
  padding: 30px 20px;
}
.el-row {
  display: flex;
  flex-wrap: wrap;
}
.el-col {
  flex: 0 0 25%;
  margin-bottom: 15px;
}
.radio {
  display: block;
}
.radio_flex {
  display: flex;
  height: 60px;
  align-items:center;
  justify-content: space-between;
}
.radio_flex_col{
  display: flex;
  flex-direction: column;
  margin-top: 20px;
}
::v-deep .el-radio__input.is-checked+.el-radio__label{
display: inline-block;
}
</style>
